//
//  BZPublicVC.m
//  QuickCure
//
//  Created by brice Mac on 16/9/15.
//  Copyright © 2016年 haoge. All rights reserved.
//
//  公益就是个WebView,直接加载网址就行了，里面的内容不用自己写！！！
//  http://202.106.210.115:18080/hyde-pluto-h360/nt/appEntrance.htm

#import "BZPublicVC.h"
#import "SVProgressHUD.h"

@interface BZPublicVC ()<UIWebViewDelegate>

@property(weak,nonatomic)UIWebView *webView;

@end

@implementation BZPublicVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpUI];
}

- (void)setUpUI {
    
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    self.view = webView;
    self.webView = webView;
    webView.delegate = self;
    
    NSURL *url = [NSURL URLWithString:@"http://202.106.210.115:18080/hyde-pluto-h360/nt/appEntrance.htm"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setTimeoutInterval:15.0f];
    
    [webView loadRequest:request];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    
    UIVisualEffectView *visualE = [[UIVisualEffectView alloc]initWithFrame:self.webView.bounds];
    
    visualE.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
    
    visualE.tag = 2016;
    
    [self.view addSubview:visualE];
    
    [SVProgressHUD show];
    
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setBackgroundColor:[UIColor darkGrayColor]];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    
    [SVProgressHUD setFadeInAnimationDuration:0.5];
    
    [SVProgressHUD setFadeOutAnimationDuration:0.5];
}



- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    UIVisualEffectView *visualE = [self.webView viewWithTag:2016];
    
    [SVProgressHUD dismiss];
    
    [visualE removeFromSuperview];
}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    UIVisualEffectView *visualE = [self.webView viewWithTag:2016];
    [visualE removeFromSuperview];
    
    [SVProgressHUD dismiss];
    
    [SVProgressHUD show];
    
    [SVProgressHUD showErrorWithStatus:@"网络连接失败.."];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [SVProgressHUD setFadeOutAnimationDuration:1];
        [SVProgressHUD dismiss];
        [self.navigationController popViewControllerAnimated:YES];
    });
}

@end





